--[[
  author: blog.163.com/mr_zyf/
]]

require "tools/extern"
local GameOverLayer=class("GameOverLayer",function()
    return CCLayerColor:create(ccc4(255,255,255,125))
end)
GameOverLayer.__index=GameOverLayer
function GameOverLayer:lInit()
   local that=self
   local winSize=CCDirector:sharedDirector():getVisibleSize()
   local label=CCLabelTTF:create("", "Arial", 12)
   label:setColor(ccc3(0,0,0))
   label:setPosition(ccp(winSize.width/2,winSize.height/2))
   self:addChild(label)
   label:retain()
   self.label=label
    --onNodeEvent
   local function onNodeEvent(event)
     cclog("gameOverLayer event:"..event)
     if event=="cleanup" then
        that:lcleanUp()
     end
   end
   self:registerScriptHandler(onNodeEvent)
   local actionDelayTime=CCDelayTime:create(3)
   local that=self
   local function gameOverDone()
      that:gameOverDone()
   end
   local actionCallFuncDone=CCCallFuncN:create(gameOverDone)
   self:runAction(CCSequence:createWithTwoActions(
       actionDelayTime,
       actionCallFuncDone
   ))
end
function GameOverLayer:setString(str)
  if self.label then
    self.label:setString(str)
  end
end
function GameOverLayer:lcleanUp()
  if self.label then
    self.label:release()
    cclog("gameOverLayer label release!")
  end
  cclogSave()
end
function GameOverLayer:gameOverDone()
    local scene=CCScene:create()
    local GameLayer=require("gameLayer")
    local layer=GameLayer:lCreate()
    scene:addChild(layer)
    CCDirector:sharedDirector():replaceScene(scene) 
end
function GameOverLayer:lCreate()
   local o=GameOverLayer.new()
   o:lInit()
   return o
end
return GameOverLayer
